// pages/knowledge/videoPage/videoPage.js
const {imgUrl} = getApp().globalData
import {knowledgeApi} from '@/utils/request/api/knowledge'

Page({

    /**
     * 页面的初始数据
     */
    data: {
        imgUrl: imgUrl + 'knowledge/',
        videoShoping: false,
        courseTab: 0,
        courseTitleList: [
            {
                name: "目录",
                value: "0"
            },
            {
                name: "资料下载",
                value: "1"
            },
            {
                name: "笔记",
                value: "2"
            },
            {
                name: "评价",
                value: "3"
            }
        ],
        courseList: [

            {
                name: "1.1 建筑业与建筑项目",
                value: 0
            },
            {
                name: "1.2 工程造价的含义",
                value: 1
            },
            {
                name: "1.3 工程造价管理",
                value: 2
            },
            {
                name: "1.4 我国注册造价工程师制度",
                value: 3
            },
            {
                name: "2.1 资金的时间价值概念",
                value: 4
            },
            {
                name: '2.2 资金的时间价值计算',
                value: 5
            },
            {
                name: '2.3 资金的时间价值应用',
                value: 6
            },
            {
                name: '2.4 技术方案评价',
                value: 7
            },
            {
                name: '3.1 概述',
                value: 8
            },
            {
                name: '3.2 建筑安装费用',
                value: 9
            },
            {
                name: '3.3 设备及工、器具购置费',
                value: 10
            },
            {
                name: '3.4 工程建设及其他费用',
                value: 11
            },
        ],
        datumNum: 0,
        datumList: [
            {
                name: '全部资料',
                value: 0
            },
            {
                name: '课程资料',
                value: 1
            },
            {
                name: '课时1',
                value: 2
            },
        ],
        datunFileList: [
            {
                name: '文件名称XXXXXXX.doc',
                type: 1,
                img: 'excel'
            },
            {
                name: '文件名称XXXXXXX.doc',
                type: 2,
                img: "pdf"
            },
            {
                name: '文件名称XXXXXXX.doc',
                type: 2,
                img: "word"
            },
            {
                name: '文件名称XXXXXXX.doc',
                type: 2,
                img: "link"
            },
        ],
        notesNums: 0,
        notesList: [
            {
                name: "全部笔记",
                value: 0
            },
            {
                name: "课程笔记",
                value: 1
            },
            {
                name: "课时1",
                value: 2
            },
        ],
        informShow: false,
        videoID: "1",
        videoArr: {},
        commentList: [],  //评论列表
        notesArrList: [],  //笔记列表
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad(options) {
        console.log(`options==`,options)
        if (options.ids) {
            this.setData({
                videoID: options.ids
            })
            this.queryVideo()

        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady() {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow() {
        // this.queryVideo()
        this.videoComment()
        this.videoNotes()
    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide() {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload() {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh() {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom() {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage() {

    },
    clickTabes(evn) {
        this.setData({
            courseTab: evn.currentTarget.dataset.values
        })
    },
    clickVideoCourse(evn) {
        this.setData({
            courseIndex: evn.currentTarget.dataset.values.value
        })
    },
    notesFun(evn) {
        this.setData({
            notesNums: evn.currentTarget.dataset.values.value
        })
    },
    //举报
    informEvaluate() {
        this.setData({
            informShow: true
        })
    },
    closeInformEvaluate() {
        this.setData({
            informShow: false
        })
    },
    async queryVideo() {
        //查询课程接口
        let res = await knowledgeApi.courseUrl('info', {id: this.data.videoID})
        if (res.err_code == 0) {
            this.setData({
                videoArr: res.data.course,
                courseList: res.data.chapters
            })
            this.getVideoStatus()
        }else{
            this.getVideoStatus()
        }
    },
    async getVideoStatus() {
        let res = await knowledgeApi.userUrl('buy_status', {course_id: this.data.videoID})
        if (res.data.err_code == 0) {
            this.setData({
                videoShoping:res.data.is_buy
            })

        }
    },
    async videoComment() {
        //评价接口
        let res = await knowledgeApi.courseUrl('comment/list', {course_id: this.data.videoID})
        if (res.err_code == 0) {
            this.setData({
                commentList: res.data.list
            })
        }
    },
    async videoNotes() {
        //评价接口
        let res = await knowledgeApi.courseUrl('note/list', {course_id: this.data.videoID})
        if (res.err_code == 0) {
            this.setData({
                notesArrList: res.data.list
            })
        }
    },

    async bindPurchase(){
        let res = await knowledgeApi.postCourseUrl('buy', {course_id: this.data.videoID})
        if(res.err_code == 0){
            wx.showToast({
                title: '购买成功',  // 标题
                duration: 1500   // 图标停留时间，默认1500ms
            })
            this.getVideoStatus()
            this.queryVideo()
        }else{

        }
    },

})